/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package scriptedsands;

import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.codehaus.janino.*;
import org.python.util.PythonInterpreter;

/**
 *
 * @author Dalton
 */


public class Main {

    /**
     * @param args the command line arguments
     */

    public static void main(String[] args) {
        new Main().start();
    }

    public void start() {
        try {
            String engineClass;
            String guiClass;
            PythonInterpreter interp = new PythonInterpreter();
            interp.execfile("settings.ini");
            engineClass = interp.get("engine").asString();
            guiClass = interp.get("gui").asString();
            ClassLoader cl = new JavaSourceClassLoader(
                    this.getClass().getClassLoader(),
                    new File[]{new File(System.getProperty("user.dir")+"/scripts")},
                    (String) null,
                    DebuggingInformation.NONE);
            AbstractEngine engine = (AbstractEngine) cl.loadClass(engineClass).newInstance();
            AbstractGUI gui = (AbstractGUI) cl.loadClass(guiClass).newInstance();
            gui.setEngine(engine);
            engine.start();
            gui.start();
        } catch (InstantiationException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
